/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   * */
  // eslint-disable-next-line no-multi-assign
  const config = (exports = {});

  // config/config.${env}.js

  config.mysql =
    process.env.NODE_ENV === 'development'
      ? {
          // 单数据库信息配置
          client: {
            // host
            host: 'localhost',
            // 端口号
            port: '3306',
            // 用户名
            user: 'root',
            // 密码
            password: '123456',
            // 数据库名
            database: 'test',
          },
          // 是否加载到 app 上，默认开启
          app: true,
          // 是否加载到 agent 上，默认关闭
          agent: false,
        }
      : {
          // 单数据库信息配置
          client: {
            // host
            host: 'localhost',
            // 端口号
            port: '3306',
            // 用户名
            user: 'test19373110',
            // 密码
            password: '123456',
            // 数据库名
            database: 'test19373110',
          },
          // 是否加载到 app 上，默认开启
          app: true,
          // 是否加载到 agent 上，默认关闭
          agent: false,
        };
  // use for cookie sign key, should change to your own and keep security
  config.keys = `${appInfo.name}_1675149085912_2053`;

  // add your middleware config here
  config.middleware = ['errorHandle', 'acl', 'projectAcl', 'resultFormat'];

  config.cors = {
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
    origin: '*',
  };

  config.acl = {
    ignore: /^\/(login|register|client)/,
  };
  config.projectAcl = {
    ignore: [
      '/login',
      '/register',
      '/username',
      '/project/list',
      '/project/list/stared',
      '/project/create',
      /^\/client/,
    ],
  };
  config.security = {
    csrf: {
      enable: false,
    },
  };

  config.io = {
    init: {}, // passed to engine.io
    namespace: {
      '/': {
        connectionMiddleware: ['errorHandle', 'auth'],
        packetMiddleware: [],
      },
    },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
